//-----------------------------------------------------------------------------
// File: ReflectionPropertyDescriptor.cs
//
// Copyright (c) Dmitry Shuklin. All rights reserved.
//-----------------------------------------------------------------------------
using System;

namespace ObjectiveDraw.Platform.Serialization
{
	/// <summary>
	/// Summary description for ReflectionPropertyDescriptor.
	/// </summary>
	public class ReflectionPropertyDescriptor : System.ComponentModel.PropertyDescriptor 
	{
		System.Reflection.PropertyInfo m_PropertyInfo;
		public ReflectionPropertyDescriptor(string attributeName, System.Attribute [] attributes, System.Reflection.PropertyInfo propertyInfo) : base(attributeName, attributes)
		{
			m_PropertyInfo = propertyInfo;
		}

		public override bool CanResetValue(object component)
		{
			return false;
		}

		public override object GetValue(object component)
		{
			return m_PropertyInfo.GetValue(component, null);
		}

		public override bool IsReadOnly
		{
			get
			{
				return !m_PropertyInfo.CanRead;
			}
		}

		public override void ResetValue(object component)
		{

		}

		public override void SetValue(object component, object value)
		{
			m_PropertyInfo.SetValue(component, value, null);
		}

		public override bool ShouldSerializeValue(object component)
		{
			return false;
		}

		public override Type PropertyType
		{
			get
			{
				return m_PropertyInfo.PropertyType;
			}
		}

		public override Type ComponentType
		{
			get
			{
				return m_PropertyInfo.ReflectedType;
			}
		}
	}
}
